home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / C_Language / Open / Common / MAIN.CPP next >
C/C++ Source or Header  |  1996-08-12  |  6KB  |  271 lines

  1. /*
  2.  *--- main.cpp ----------------------------------------------------------
  3.  * Copyright (c) 1992-96 Adobe Systems, Inc.  All rights reserved.
  4.  *
  5.  * PageMaker plug-in OpenCopy.
  6.  *-----------------------------------------------------------------------
  7.  */
  8.  
  9. /* ---------------- PageMaker SDK include files ---------------- */
  10. #include "PMPlugin.h"
  11. #include "opencpy.h"
  12.  
  13. /* ---------------- Plug-in include files ---------------- */
  14. #ifdef MACINTOSH
  15.     #include "WinTypes.h"
  16. #endif // MACINTOSH
  17.  
  18. /* ---------------- Cross-platform include files ---------------- */
  19. #include <string.h>
  20. #include <stdio.h>
  21.  
  22. /* ---------------- Platform specific include files ---------------- */
  23. #ifdef MACINTOSH
  24.     #include <types.h>
  25.     #ifndef powerc
  26.         #include <A4Stuff.h>
  27.         #include <SetUpA4.h>
  28.     #endif
  29. #else
  30.     #include <windows.h>
  31. #endif
  32.  
  33. /* ---------------- Type definitions ---------------- */
  34.  
  35. /* ---------------- Definitions ---------------- */
  36. #define SUCCESS            1
  37. #define FAILURE            0
  38. #define STAYINMEMORY    -1
  39.  
  40. #define BUG_IN_HEADER
  41.  
  42. /* ---------------- PageMaker (New)SDK include files ---------------- */
  43. #include "CIInterfaceManager.h"
  44. #include "PMEvent.h"
  45. #include "PMEventRec.h"
  46. #include "CIBasic.h"
  47. #include "PMInterfaceIDs.h"
  48. #include "CICommandsAndQueries.h"
  49.  
  50. /* ---------------- Function declarations ---------------- */
  51. PMXErr DoInvoke( PMMessage *pMsg );
  52. PMXErr DoLoad(PMMessage* pMsg);
  53. PMXErr DoRegister(PMMessage* pMsg);
  54. PMXErr DoInvoke(PMMessage* pMsg);
  55. PMXErr DoEvent(PMMessage* pMsg);
  56. PMXErr DoSysEvent(PMMessage* pMsg);
  57. PMXErr DoAcquireInterface(PMMessage* pMsg);
  58. PMXErr DoReleaseInterface( PMMessage *pMsg );
  59. PMXErr DoUnload(PMMessage* pMsg);
  60. PMXErr DoShutdown(PMMessage* pMsg);
  61. PMXErr DoCleanup(PMMessage* pMsg);
  62.  
  63. #ifdef MACINTOSH
  64.     #ifdef powerc
  65.         #pragma export on
  66.     #endif
  67.         PMXErr main(PMMessage *pMsg);
  68.     #ifdef powerc
  69.         #pragma export off
  70.     #endif
  71. #else
  72.     BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved);
  73. #endif
  74.  
  75. /* ---------------- Globals ---------------- */
  76. sPMParamBlockPtr thePB = NULL;
  77. CIInterfaceManager    *gpIntfMgr = (CIInterfaceManager *) NULL;
  78.  
  79. #ifdef WINDOWS
  80.     HINSTANCE ghDLL;
  81.  
  82. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved)
  83. {
  84.     ghDLL = hDLL;
  85.  
  86.     return TRUE;
  87. }
  88. #endif
  89.  
  90. /*
  91.  *--- main --------------------------------------------------------------------
  92.  *  Entry point for plug-in control tasks.
  93.  *-----------------------------------------------------------------------------
  94.  */ 
  95. PMXErr main(PMMessage *pMsg)
  96. {
  97.     PMXErr    result;
  98. #if __MWERKS__ && __MC68K__
  99.     long oldA4 = SetCurrentA4();
  100.     RememberA4();
  101. #endif
  102.  
  103.     gpIntfMgr = pMsg->pInterfaceMgr;
  104.     
  105.     switch ( pMsg->opCode ) {
  106.         case kPMLoad: 
  107.             result = DoLoad(pMsg);
  108.             break;
  109.  
  110.         case kPMRegister: 
  111.             result = DoRegister(pMsg);
  112.             break;
  113.             
  114.         case kPMInvoke: 
  115.             result = DoInvoke(pMsg);
  116.             break;
  117.  
  118.         case kPMEvent: 
  119.             result = DoEvent(pMsg);
  120.             break;
  121.             
  122.         case kPMSysEvent: 
  123.             result = DoSysEvent(pMsg);
  124.             break;
  125.             
  126.         case kPMAcquireInterface: 
  127.             result = DoAcquireInterface(pMsg);
  128.             break;
  129.             
  130.         case kPMReleaseInterface: 
  131.             result = DoReleaseInterface(pMsg);
  132.             break;
  133.             
  134.         case kPMUnload: 
  135.             result = DoUnload(pMsg);
  136.             break;
  137.  
  138.         case kPMShutdown: 
  139.             result = DoShutdown(pMsg);
  140.             break;
  141.             
  142.         case kPMCleanup: 
  143.             result = DoCleanup(pMsg);
  144.             break;
  145.             
  146.         default: 
  147.             result = 0;
  148.     }
  149.  
  150. #if __MWERKS__ && __MC68K__
  151.     SetA4(oldA4);
  152. #endif
  153.  
  154.     return result;
  155. }
  156.  
  157. PMXErr DoRegister( PMMessage *pMsg )
  158. {
  159.     PMXErr     result = SUCCESS;
  160.     CIBasic    *pBasic;
  161.     
  162.     gpIntfMgr = pMsg->pInterfaceMgr;
  163.     
  164.     result = gpIntfMgr->AcquirePMInterface((DWORD)PMIID_BASIC,
  165.                                             (LPVOID *)&pBasic);
  166.                                                     
  167.     pBasic->RegisterPMEvent(PMEVT_MENUCOMMAND_BEFORE);
  168.  
  169.     gpIntfMgr->ReleasePMInterface((LPVOID)pBasic);
  170.  
  171. onErr:
  172.     return result;
  173. }
  174.  
  175. PMXErr DoAcquireInterface( PMMessage *pMsg )
  176. {
  177.     PMXErr result = SUCCESS;
  178.     gpIntfMgr = pMsg->pInterfaceMgr;
  179.  
  180.     return result;
  181. }
  182.  
  183. PMXErr DoReleaseInterface( PMMessage *pMsg )
  184. {
  185.     PMXErr result = SUCCESS;
  186.     gpIntfMgr = pMsg->pInterfaceMgr;
  187.             
  188.     return result;
  189. }
  190.  
  191. PMXErr DoInvoke( PMMessage *pMsg )
  192. {
  193.     PMXErr result = SUCCESS;
  194.  
  195.     gpIntfMgr = pMsg->pInterfaceMgr;
  196.  
  197.     return result;
  198. }
  199.  
  200. PMXErr DoLoad(PMMessage* pMsg)
  201. {
  202.     PMXErr result = SUCCESS;
  203.     gpIntfMgr = pMsg->pInterfaceMgr;
  204.         
  205.     return result;
  206. }
  207.  
  208. PMXErr DoEvent(PMMessage* pMsg)
  209. {
  210.     PMXErr result = SUCCESS;
  211.     PMEvent *pEvt = (PMEvent *)pMsg->pPMData;
  212.     PPMEVT_MENUCOMMAND_REC pMenu;
  213.     CICommandQuery *pCmdQry = (CICommandQuery *)NULL;
  214.     
  215.     gpIntfMgr = pMsg->pInterfaceMgr;
  216.     
  217.     if (pEvt->eventID == PMEVT_MENUCOMMAND_BEFORE) {
  218.          pMenu = (PPMEVT_MENUCOMMAND_REC)pEvt->lParm;
  219.          if (pMenu->menuGroupID == 512 && pMenu->menuItemID == 514) { //Open Menu Item
  220.  
  221.             if (!gpIntfMgr->AcquirePMInterface(PMIID_CMDQRY, (LPVOID *)&pCmdQry))
  222.                 pCmdQry->Retrieve (&thePB);
  223.             else
  224.                 return CQ_FAILURE;
  225.  
  226.              if (pEvt->wasHandled != TRUE)
  227.                  OpenPubCopy();
  228.  
  229.             gpIntfMgr->ReleasePMInterface((LPVOID *)pCmdQry);
  230.  
  231.              pEvt->wasHandled = TRUE;
  232.          }
  233.     } else {
  234.         pEvt->wasHandled = FALSE;
  235.     }
  236.     
  237.     return result;
  238. }
  239.  
  240. PMXErr DoSysEvent(PMMessage* pMsg)
  241. {
  242.     PMXErr result = SUCCESS;
  243.     gpIntfMgr = pMsg->pInterfaceMgr;
  244.         
  245.     return result;
  246. }
  247.  
  248. PMXErr DoUnload(PMMessage* pMsg)
  249. {
  250.     PMXErr result = STAYINMEMORY;
  251.     gpIntfMgr = pMsg->pInterfaceMgr;
  252.         
  253.     return result;
  254. }
  255.  
  256. PMXErr DoShutdown(PMMessage* pMsg)
  257. {
  258.     PMXErr result = SUCCESS;
  259.     gpIntfMgr = pMsg->pInterfaceMgr;
  260.         
  261.     return result;
  262. }
  263.  
  264. PMXErr DoCleanup(PMMessage* pMsg)
  265. {
  266.     PMXErr result = SUCCESS;
  267.     gpIntfMgr = pMsg->pInterfaceMgr;
  268.         
  269.     return result;
  270. }
  271.